<%@ Language=VBScript %>
<%
btungay=Request("btungay")
bdenngay=Request("bdenngay")
if  btungay<>"" and bdenngay <>"" then
	bngay="Từ ngày  " + btungay + "  đến ngày  " + bdenngay
else
	bngay=" "
end if
	sSQL=Request("PrintValue")
	if sSQL="" then
		sSQL="select * from vtdi"
	end if
	sSQL=sSQL+" order by so,ngayky"
	CAll RP("rptVTDi.rpt",sSQL)	
%>
<!-- #include file="SmartViewerActiveX.asp" -->
<script language=vbscript runat=server>
	Function FormatDate(vDate)
	   If Not IsNull(vDate) Then
	        vM = Right("0" & Month(vDate), 2)
	        vD = Right("0" & Day(vDate), 2)
	        vY = Right("19" & Year(vDate), 4)
	        FormatDate = vD & "/" & vM & "/" & vY
	   End If
	End Function
	Function SaveDate(vDate)
		dim bvitri1
		dim bvitri2
	   vDate=trim(cstr(vDate))
	   bvitri1=instr(1,vDate,"/")
	   bMonth=left(vDate,bvitri1-1)
	   bvitri2=instr(bvitri1+1,vDate,"/")
	   Dim Temp
	   Temp=right(vDate,len(vDate)-bvitri1)
	   bDay=left(Temp,bvitri2-bvitri1-1)
	   bYear=right(vDate,len(vDate)-bvitri2)
       SaveDate=bDay+"/"+bMonth+"/"+bYear
	End Function
function RP(inReportName,inSQL)
	ReportName = Session("APPL_PHYSICAL_PATH") & "\report\" &inReportName
	
	If Not IsObject ( session("oApp") ) Then
	    Set session ("oApp") = Server.CreateObject("CrystalRuntime.Application")
	End If

	If IsObject(session("oRpt")) then
		Set session("oRpt") = nothing
	End if	

	Set session("oRpt") = session("oApp").OpenReport(ReportName,1)
	session("oRpt").MorePrintEngineErrorMessages = False
	session("oRpt").EnableParameterPrompting = False
	session("oRpt").DiscardSavedData
	
	Session("oRpt").Database.Tables(1).ConnectionProperties("Data Source") = Application("DataSource")
	Session("oRpt").Database.Tables(1).ConnectionProperties("Initial Catalog") =Application("DataBaseName")	
	Session("oRpt").Database.Tables(1).ConnectionProperties("User ID") = Application("DBUser")
	Session("oRpt").Database.Tables(1).ConnectionProperties("Password") = Application("DBPass")
	
	session("oRpt").ParameterFields(1).SetCurrentValue cstr(bngay)

	session("oRpt").SQLQueryString = CStr(inSQL)	
	If Err.Number <> 0 Then
	    Response.Write "Error " & Err.number & " " & Err.description 
	Else
	    If IsObject(session("oPageEngine")) Then
     	   set session("oPageEngine") = nothing
	    End If
	    set session("oPageEngine") = session("oRpt").PageEngine
	End If
end function
</SCRIPT>